import Vue from "vue"

export default new Vue({
  methods: {
    data() {
      return {
      }
    },
    emit(event, ...args) {
      this.$emit(event, ...args)
    },
    on(event, cb) {
      this.$on(event, cb)
    },
    off(event) {
      this.$off(event)
    },
    tip(msg = '操作成功！', type = 'info', time = 2000, ctrl = true) {
      this.$message({
        message: msg,
        showClose: ctrl,
        duration: time,
        type: type,
        customClass: 'tip-message'
      })
    },
    delay(cb, time) {
      setTimeout(cb , time || 1000)
    },
    throttle(cb, time) {
      if (this.timer) {
        clearTimeout(this.timer)
        this.timer = null
      }
      this.timer = setTimeout(() => {
        cb()
        clearTimeout(this.timer)
        this.timer = null
      }, time)
    },
    open(cb, text= '您是否确认当前操作? 是否继续?', title = '警告', ccb = () =>{} ) {
      return this.$confirm(text, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(cb).catch(ccb)
    },
    notify(type, title, msg) {
      msg = msg || '您无此权限，套餐未包含此功能！点击这里前往开通'
      this.$notify({
        title: title || '警告',
        type: type || 'warning',
        position: 'top-left',
        customClass: 'notify-tips',
        dangerouslyUseHTMLString: true,
        message: '<a style="color:#409EFF" href="' + $globalconfig.URLS.USER + 'Package/Index.aspx" target="_blank">'+ msg +'</a>'
      })
    },
    openLoading(target, text = 'Loading', spinner = 'el-icon-loading', background = 'rgba(255, 255, 255, 0.7)') {
      if (this.loading) return
      this.loading = this.$loading({
        target: target == 1 ? '#app .router-view' : target,
        lock: true,
        text,
        spinner,
        background 
      })
    },
    closeLoading() {
      if (this.loading) {
        this.loading.close()
        this.loading = null
      }
    }
  }
})